<?php
namespace Org\Util;
class Ums{
    /**
     * 一信通 短信接口
     */
    protected $testtxt='您的验证码为123456';//测试模板
    protected $mobile;
    protected $text;//短信内容
    protected $company="【515学车网】";
    protected $ch;
    protected $username='admin2';//短信账号用户名 密码
    protected $password='zhonghengkeji123';
    protected $SpCode='235038';//企业编号
    protected $SerialNumber;//流水号，与回执接口中的流水号一一对应，不传后面回执接口无法查询数据
    protected $url='https://api.ums86.com:9600/sms/Api/Send.do';//接口地址

    public function __construct($mobile,$text,$serialnumber) {
        $this->ch=curl_init();
        /* 设置验证方式 */
        curl_setopt($this->ch, CURLOPT_HEADER, false);
        curl_setopt( $this->ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
        /* 设置返回结果为流 */
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($this->ch, CURLOPT_POST, 1);
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
        $this->text=$text;
        $this->mobile=$mobile;
        $this->SerialNumber=$serialnumber;
    }
    // 发送短信
    public function send(){
        $reqdata=array(
            'SpCode'=>$this->SpCode,
            'LoginName'=>$this->username,
            'Password'=>$this->password,
            'MessageContent'=>$this->text,
            'UserNumber'=>$this->mobile,
            'SerialNumber'=>$this->SerialNumber,
            'ScheduleTime'=>''
        );
        foreach ($reqdata as $k=>$v){
            $reqdata[$k]=iconv("UTF-8","gbk//TRANSLIT",$reqdata[$k]);
        }
        $reqdata=http_build_query($reqdata);
        curl_setopt ($this->ch, CURLOPT_URL,$this->url);
        curl_setopt($this->ch, CURLOPT_POSTFIELDS, $reqdata);
        $ret=curl_exec($this->ch);
        curl_close($this->ch);
//        $ret=json_decode($ret,1);
//        var_dump(curl_error($this->ch));
        parse_str($ret,$arr);
        return $arr;//返回结果数组 array('result'=>0,'description'=>'发送短信成功');
    }
}